from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
from postion import options
from postion import service

driver = webdriver.Chrome(options=options,service=service)
driver.get(r'https://www.baidu.com/')
sleep(3)
print('当前窗口的句柄是：')
print(driver.current_window_handle)

driver.find_element(By.LINK_TEXT,'hao123').click()
sleep(3)
print('当前窗口的句柄是：')
print(driver.current_window_handle)

baidu_handle=driver.window_handles[0]
hap123_handle=driver.window_handles[1]
#切换到百度
driver.switch_to.window(baidu_handle)
sleep(6)
#切换到hao123
driver.switch_to.window(hap123_handle)
sleep(3)
print('所有窗口的句柄是')
print(driver.window_handles)

driver.quit()